<template>
<div>
<home-header></home-header>
<home-swiper :list = "swiperList"></home-swiper>
<home-icons :list = "iconList"></home-icons>
<home-recommend :list = "recommendList"></home-recommend>
<home-weekend :list = "weekendList"></home-weekend>
</div>
</template>
<script>
import homeHeader from './components/homeHeader'
import homeSwiper from './components/homeSwiper'
import homeIcons from './components/homeIcons'
import homeRecommend from './components/homeRecommend'
import homeWeekend from './components/homeWeekend'
import axios from 'axios'
import { mapState } from 'vuex'
export default {
  name: 'home',
  components: {
    homeHeader,
    homeSwiper,
    homeIcons,
    homeRecommend,
    homeWeekend
  },
  data () {
    return {
      swiperList: [],
      iconList: [],
      recommendList: [],
      weekendList: []
    }
  },
  computed: {
    ...mapState(['city'])
  },
  methods: {
    getHomeInfo () {
      axios.get('/static/mock/index.json?city=' + this.city)
        .then(this.getHomeInfoSucc)
    },
    getHomeInfoSucc (res) {
      // console.log(res)
      res = res.data
      if (res.ret && res.data) {
        this.swiperList = res.data.swiperList
        this.iconList = res.data.iconList
        this.recommendList = res.data.recommendList
        this.weekendList = res.data.weekendList
      }
    }
  },
  mounted () {
    this.lastCity = this.city
    this.getHomeInfo()
    console.log('mounted')
    console.log('this.lastCity:' + this.lastCity)
  },
  activated () {
    console.log('activited')
    if (this.lastCity !== this.city) {
      this.lastCity = this.city
      this.getHomeInfo()
      console.log('lastCity:' + this.lastCity)
    }
  }
}
</script>
<style></style>
